﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="ReBuilderOrder.aspx.cs" Inherits="UI_Orders_ReBuilderOrder" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>订单重发</title>
    <script src="../../js/common.js" type="text/javascript"></script>
    <link href="../../css/admin.css" rel="stylesheet" type="text/css" />
    <link href="../../js/jquery.easyui/themes/default/easyui.css" rel="stylesheet" type="text/css" />
    <link href="../../js/jquery.easyui/themes/icon.css" rel="stylesheet" type="text/css" />
    <script src="../../js/jquery.easyui/jquery.min.js" type="text/javascript"></script>
    <script src="../../js/jquery.easyui/jquery.easyui.min.js" type="text/javascript"></script>
    <script src="../../js/jquery.easyui/locale/easyui-lang-zh_CN.js" type="text/javascript"></script>
        <script type="text/javascript">
            function qchange(t, rowIndex) {
                var rows = $("#t_orderdetail").datagrid('getRows');
                var row = rows[rowIndex];
                if (parseInt(t.value, 0) > parseInt(row.Quantity, 0)) {
                    alert('数量太大'); 
                    t.value = 0;
                }
                else {
                    row.Qty = t.value;
                }
            }
            $(function () {
                $("#divOrder").panel({
                    //width: 590,
                    //height:390,
                    width: 855,
                    height: 390,
                    title: "订单号:" + $("#txtOrderId").val()
                });
                $("#t_orderdetail").datagrid({
                    border: true,
                    // height: 200,
                    // width: 580,
                    height: 200,
                    width: 850,
                    title: '产品明细...',
                    remoteSort: false,
                    nowrap: true,
                    striped: false,
                    url: "../../TableHanders.aspx?act=q&tid=1020&type=0",
                    loadMsg: "正在加载,请稍后...",
                    columns: [[
                        { field: 'ck', title: '', checkbox: true },
	                    { title: '商品代号', field: 'ProductId', width: 80 },
	                    { title: '商品名称', field: 'ProductName', width: 280 },
                        { title: '商品规格', field: 'ProductSpecification', width: 180 },
	                    { title: '重发数量', field: 'Qty', width: 80, formatter: function (val, rec, rowIndex) {
	                        return '<input value = "' + val + '" onchange = "qchange(this,' + rowIndex + ');"></input>';
	                    }
	                    },
	                    { title: '商品数量', field: 'Quantity', width: 80
	                    },
                        { title: '锁定库存', field: 'SQty', width: 80 },
                        { title: '库存数量', field: 'FQty', width: 80 },
	                    { title: '商品价格', field: 'SalePrice', width: 100 }
				    ]],
                    queryParams: {
                        "OrderId": $("#txtOrderId").val(),
                        "ebayUserId": $("#txtEbayUserId").val()
                    }
                });
                $("#btnOK").click(function () {
                    var rows = $("#t_orderdetail").datagrid('getSelections');
                    if (rows.length == 0) {
                        alert('至少选择一个产品');
                        return;
                    }

                    var data = [];
                    var row = {};
                    var pdata = {};
                    for (var i = 0; i < rows.length; i++) {
                        var quantity = rows[i].Qty;
                        if (quantity <= 0) {
                            alert('数量必须大于0');
                            return;
                        }
                        if (parseInt(quantity, 0) > parseInt(rows[i].Quantity, 0)) {
                            alert('发货数量不能大于原数量');
                            return;
                        }
                        row = rows[i];
                        row.Quantity = quantity;
                        data[data.length] = row;
                    }
                    pdata.buyerName = $("#txtBuyerName").val();
                    pdata.orderId = $("#txtOrderId").val();
                    pdata.ebayUserId = $("#txtEbayUserId").val();
                    pdata.addr1 = $("#textBoxAddresserLine1").val();
                    pdata.addr2 = $("#textBoxAddresserLine2").val();
                    pdata.PostageService = $("#ddlDeliveryId").val();
                    pdata.reson = $("#ddlreson").val();

                    //新添加的字段
                    pdata.City = $("#txtCity").val();
                    pdata.County = $("#txtCounty").val();
                    pdata.PostalCode = $("#txtPostalCode").val();
                    pdata.Country = $("#txtCountry").val();
                    var item = $('input:[name=SendType]:checked').val();
                    switch (item) {
                        case "rdSent":
                            pdata.Type = "Y";
                            break;
                        case "rdToSend":
                        default:
                            pdata.Type = "N";
                            break;
                    }

                    if (pdata.buyerName == "") {
                        alert('买家姓名不能为空');
                        return;
                    }
                    if (pdata.PostageService == "") {
                        alert('发货方式不能为空');
                        return;
                    }
                    if (pdata.reson == "0") {
                        alert('重发原因不能为空');
                        return;
                    }
                    $("#btnOK").attr('disabled', "true");
                    var url = "OrdersHandler.ashx?cmd=ddcfa&ts=" + new Date().getTime();
                    $.getJSON(
                    url,
                    { 'pd': $.toJSON(pdata), 'data': $.toJSON(data) },
                    function (data) {
                        var retData = EvalData(data);
                        var code = retData.retCode;
                        if (code == 0) {

                            alert('操作完成');
                            window.returnValue = true;
                            window.close();
                        }
                        else {
                            alert(retData.retMsg);
                        }
                    });
                });
            });
    </script>
    <style type="text/css">
        #txtreson
        {
            width: 450px;
        }
        input
        {
            width: 180px;
        }
        select
        {
            width: 186px;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server" style = "margin-left:10px">
    <div id = "divOrder">
    <input type = "hidden" id="txtEbayUserId" runat="server" />
    <input type = "hidden" id="txtOrderId" runat="server" />
    <table>
    <tr>
        <td>买家姓名:</td>
        <td><input type = "text" runat="server" id = "txtBuyerName" /></td>
        <td>County:</td>
        <td><input type = "text" runat="server" id = "txtCounty" /></td>        
         <td>地址1:</td>
        <td><input type = "text" runat="server" id = "textBoxAddresserLine1" style=" width:274px;" /></td>     
    </tr>
    <tr>
        <td>City:</td>
        <td><input type = "text" runat="server" id = "txtCity" /></td> 
        <td>地址2:</td>
        <td><input type = "text" runat="server" id = "textBoxAddresserLine2" /></td>     
        <td>发货方式:</td>
        <td><select runat="server" id = "ddlDeliveryId" style=" width:280px;" /></td>
    </tr>
    <tr>       
        <td>PostalCode:</td>
        <td><input type = "text" runat="server" id = "txtPostalCode" /></td>
        <td>Country:</td>
        <td><input type = "text" runat="server" id = "txtCountry" /></td>
        <td>重发原因:</td>
        <td><select runat="server" id = "ddlreson" style=" width:280px;" /></td>    
    </tr>
    </table>
    <table id="t_sendtype">
        <td><input type=radio id = "rdToSend" runat = "server" name = "SendType" checked="true" style="width:20px;"/><label for = "rdToSend">未发货重发</label></td>
        <td><input type=radio id = "rdSent" runat = "server" name = "SendType" style="width:20px;"/><label for = "rdSent">已发货重发</label></td>
    </table>
    <table id="t_orderdetail"></table>

        <%--<tr style="text-align:left;">
            <td>重发次数:</td>
            <td><input type = "text" runat="server" id = "txtReCount" /></td>
        </tr>--%>
        <div style="text-align:right;margin-top:5px;">
         <table >
            <tr>
                <td>重发次数:</td>
                <td><input type = "text" runat="server" id = "txtReCount" disabled="true" style="width:50px;" /></td>
                <td>
                    <a href="#" id="btnOK" class="easyui-linkbutton" icon="icon-ok">提交</a>
                    <a href="#" class="easyui-linkbutton" icon="icon-cancel"  onclick="window.close();">Close</a>
                </td>
            </tr>
         </table>
        </div>
    </div>
    </form>
</body>
</html>
